package com.cskaoyan.bean.sysmanage;

import com.cskaoyan.bean.Role;
import com.github.pagehelper.PageInfo;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

@NoArgsConstructor
@Data
public class OptionsVo<T> {


    private Integer total;
    private Integer pages;
    private Integer limit;
    private Integer page;
    private List<T> list;



    @NoArgsConstructor
    @Data
    public static class RoleIdInfo {
        private Integer value;
        private String label;
    }

    public static OptionsVo ok(List<Role> roles) {
        PageInfo<Role> rolePageInfo = new PageInfo<>(roles);
        OptionsVo optionsVo = new OptionsVo<RoleIdInfo>();
        optionsVo.setTotal((int)rolePageInfo.getTotal());
        optionsVo.setPages(1);
        optionsVo.setLimit((int)rolePageInfo.getTotal());
        optionsVo.setPage(1);
        ArrayList<RoleIdInfo> roleIdInfos = new ArrayList<>();
        for (Role role : roles) {
            RoleIdInfo roleIdInfo = new RoleIdInfo();
            roleIdInfo.setValue(role.getId());
            roleIdInfo.setLabel(role.getName());
            roleIdInfos.add(roleIdInfo);
        }
        optionsVo.setList(roleIdInfos);
        return optionsVo;

    }

}
